script_enemy_main{

let charge=0;
let oldx=0;
let newx=0;
let movedir=0;
let effect1=0;
let object1=[];
let timer1=[];

let damagerate=10;
let outfit=1;
outfit=(128*outfit)-128;
let usespell=0;
let frame=0;
let time=0;
let miny=GetClipMinY; let maxy=GetClipMaxY; let minx=GetClipMinX; let maxx=GetClipMaxX;
let cx=GetCenterX; let cy=GetCenterY;

let SEshots5=("script\SoundEffects\shots5.wav");
let SEshotb5=("\script\SoundEffects\shotb5.wav");
let SEmagics5=("\script\SoundEffects\magics5.wav");

let GRfade=("\script\Images\OtherEffects\SayuriAdd.png");
let GRboss=("\script\Images\CharacterSprites\Sayuri.png");

@Initialize{
	LoadGraphic("\script\Images\OtherEffects\SayuriAdd.png");
	LoadGraphic("\script\Images\CharacterSprites\Sayuri.png");

	LoadSE("\script\SoundEffects\shots5.wav");
	LoadSE("\script\SoundEffects\shotb5.wav");
	LoadSE("\script\SoundEffects\magics5.wav");

	SetLife(10000);
	MagicCircle(false);

	SetX(GetCommonData("Boss1X"));
	SetY(GetCommonData("Boss1Y"));
	SetMovePosition02(cx-100,cy-100,60);
}
	
@MainLoop{

SetCollisionB(GetX,GetY,16);

if(time==60){ SetAngle(GetCommonData("Angle")); }


if(GetCommonData("Difficulty")==1){

if(time>=60){
SetSpeed(GetCommonData("Speed"));
	if(GetX<=minx){
	SetAngle(180-GetAngle);
	SetX(GetX+GetCommonData("Speed"));
		loop(3){
		let angle=0+rand(-80,80);
		CreateShot12(GetX,GetY,1.7*cos(angle),rand(-1,-2.5),-0.01*cos(angle),0.05,0.1*cos(angle),rand(1.2,2.2),62,0);
		}
	PlaySE(SEmagics5);
	}
	if(GetX>=maxx){
	SetAngle(180-GetAngle);
	SetX(GetX-GetCommonData("Speed"));
		loop(3){
		let angle=180+rand(-80,80);
		CreateShot12(GetX,GetY,1.7*cos(angle),rand(-1,-2.5),-0.01*cos(angle),0.05,0.1*cos(angle),rand(1.2,2.2),62,0);
		}
	PlaySE(SEmagics5);
	}
	if(GetY<=miny){
	SetAngle(-GetAngle);
	SetY(GetY+GetCommonData("Speed"));
		loop(3){
		let angle=-90+rand(-80,80);
		CreateShot12(GetX,GetY,1.7*cos(angle),rand(0,-1),-0.01*cos(angle),0.05,0.1*cos(angle),rand(1.2,2.2),62,0);
		}
	PlaySE(SEmagics5);
	}
	if(GetY>=maxy){
	SetAngle(-GetAngle);
	SetY(GetY-GetCommonData("Speed"));
		loop(3){
		let angle=-90+rand(-80,80);
		CreateShot12(GetX,GetY,1.7*cos(angle),rand(-1,-2.5),-0.01*cos(angle),0.05,0.1*cos(angle),rand(1.2,2.2),62,0);
		}
	PlaySE(SEmagics5);
	}
}

if(time%210==0 && time>=60){
let shot1=0;
let angle=0;
let speed=1.5;
let color=0;
SetShotDirectionType(PLAYER);
	loop(2){
		loop(5){
		CreateShotA(shot1,GetX+15,GetY-35,20);
		SetShotDataA(shot1,0,speed,angle,0,-0.02,0,color+74);
		SetShotDataA(shot1,60,0,0,0,0.75,2,color+74);
		FireShot(shot1);
		angle+=360/5;
		}
	angle+=360/10;
	speed-=0.5;
	color+=1;
	}
SetShotDirectionType(ABSOLUTE);
usespell=25;
PlaySE(SEshotb5);
}
if((time-110)%210==0 && time>=160){ PlaySE(SEshots5); }

} //Easy

//=============================================================================================================


if(GetCommonData("Difficulty")==2){

if(time>=60){
SetSpeed(GetCommonData("Speed"));
	if(GetX<=minx){
	SetAngle(180-GetAngle);
	SetX(GetX+GetCommonData("Speed"));
		loop(4){
		let angle=0+rand(-80,80);
		CreateShot12(GetX,GetY,1.7*cos(angle),rand(-1,-2.5),-0.01*cos(angle),0.05,0.1*cos(angle),rand(1.2,2.2),62,0);
		}
	PlaySE(SEmagics5);
	}
	if(GetX>=maxx){
	SetAngle(180-GetAngle);
	SetX(GetX-GetCommonData("Speed"));
		loop(4){
		let angle=180+rand(-80,80);
		CreateShot12(GetX,GetY,1.7*cos(angle),rand(-1,-2.5),-0.01*cos(angle),0.05,0.1*cos(angle),rand(1.2,2.2),62,0);
		}
	PlaySE(SEmagics5);
	}
	if(GetY<=miny){
	SetAngle(-GetAngle);
	SetY(GetY+GetCommonData("Speed"));
		loop(4){
		let angle=-90+rand(-80,80);
		CreateShot12(GetX,GetY,1.7*cos(angle),rand(0,-1),-0.01*cos(angle),0.05,0.1*cos(angle),rand(1.2,2.2),62,0);
		}
	PlaySE(SEmagics5);
	}
	if(GetY>=maxy){
	SetAngle(-GetAngle);
	SetY(GetY-GetCommonData("Speed"));
		loop(4){
		let angle=-90+rand(-80,80);
		CreateShot12(GetX,GetY,1.7*cos(angle),rand(-1,-2.5),-0.01*cos(angle),0.05,0.1*cos(angle),rand(1.2,2.2),62,0);
		}
	PlaySE(SEmagics5);
	}
}

if(time%180==0 && time>=60){
let shot1=0;
let angle=0;
let speed=1.5;
let color=0;
SetShotDirectionType(PLAYER);
	loop(2){
		loop(8){
		CreateShotA(shot1,GetX+15,GetY-35,20);
		SetShotDataA(shot1,0,speed,angle,0,-0.02,0,color+74);
		SetShotDataA(shot1,60,0,0,0,0.75,2.5,color+74);
		FireShot(shot1);
		angle+=360/8;
		}
	angle+=360/16;
	speed-=0.5;
	color+=1;
	}
SetShotDirectionType(ABSOLUTE);
usespell=25;
PlaySE(SEshotb5);
}
if((time-80)%180==0 && time>=160){ PlaySE(SEshots5); }

} //Normal

//=============================================================================================================

if(GetCommonData("Difficulty")==3){

if(time>=60){
SetSpeed(GetCommonData("Speed"));
	if(GetX<=minx){
	SetAngle(180-GetAngle);
	SetX(GetX+GetCommonData("Speed"));
		loop(4){
		let angle=0+rand(-80,80);
		CreateShot12(GetX,GetY,1.7*cos(angle),rand(-1,-2.5),-0.01*cos(angle),0.05,0.1*cos(angle),rand(1.2,2.2),62,0);
		}
	PlaySE(SEmagics5);
	}
	if(GetX>=maxx){
	SetAngle(180-GetAngle);
	SetX(GetX-GetCommonData("Speed"));
		loop(4){
		let angle=180+rand(-80,80);
		CreateShot12(GetX,GetY,1.7*cos(angle),rand(-1,-2.5),-0.01*cos(angle),0.05,0.1*cos(angle),rand(1.2,2.2),62,0);
		}
	PlaySE(SEmagics5);
	}
	if(GetY<=miny){
	SetAngle(-GetAngle);
	SetY(GetY+GetCommonData("Speed"));
		loop(4){
		let angle=-90+rand(-80,80);
		CreateShot12(GetX,GetY,1.7*cos(angle),rand(0,-1),-0.01*cos(angle),0.05,0.1*cos(angle),rand(1.2,2.2),62,0);
		}
	PlaySE(SEmagics5);
	}
	if(GetY>=maxy){
	SetAngle(-GetAngle);
	SetY(GetY-GetCommonData("Speed"));
		loop(4){
		let angle=-90+rand(-80,80);
		CreateShot12(GetX,GetY,1.7*cos(angle),rand(-1,-2.5),-0.01*cos(angle),0.05,0.1*cos(angle),rand(1.2,2.2),62,0);
		}
	PlaySE(SEmagics5);
	}
}

if(time%150==0 && time>=60){
let shot1=0;
let angle=0;
let speed=1.5;
let color=0;
SetShotDirectionType(PLAYER);
	loop(3){
		loop(10){
		CreateShotA(shot1,GetX+15,GetY-35,20);
		SetShotDataA(shot1,0,speed,angle,0,-0.02,0,color+74);
		SetShotDataA(shot1,60,0,0,0,0.75,3,color+74);
		FireShot(shot1);
		angle+=360/10;
		}
	angle+=360/20;
	speed-=0.5;
	color+=1;
	}
SetShotDirectionType(ABSOLUTE);
usespell=25;
PlaySE(SEshotb5);
}
if((time-80)%150==0 && time>=120){ PlaySE(SEshots5); }

} //Hard

//=============================================================================================================

if(GetCommonData("Difficulty")==4){

if(time>=60){
SetSpeed(GetCommonData("Speed"));
	if(GetX<=minx){
	SetAngle(180-GetAngle);
	SetX(GetX+GetCommonData("Speed"));
		loop(5){
		let angle=0+rand(-80,80);
		CreateShot12(GetX,GetY,2*cos(angle),rand(-1,-2.5),-0.01*cos(angle),0.05,0.1*cos(angle),rand(1.5,2.5),62,0);
		}
	PlaySE(SEmagics5);
	}
	if(GetX>=maxx){
	SetAngle(180-GetAngle);
	SetX(GetX-GetCommonData("Speed"));
		loop(5){
		let angle=180+rand(-80,80);
		CreateShot12(GetX,GetY,2*cos(angle),rand(-1,-2.5),-0.01*cos(angle),0.05,0.1*cos(angle),rand(1.5,2.5),62,0);
		}
	PlaySE(SEmagics5);
	}
	if(GetY<=miny){
	SetAngle(-GetAngle);
	SetY(GetY+GetCommonData("Speed"));
		loop(5){
		let angle=-90+rand(-80,80);
		CreateShot12(GetX,GetY,2*cos(angle),rand(0,-1),-0.01*cos(angle),0.05,0.1*cos(angle),rand(1.5,2.5),62,0);
		}
	PlaySE(SEmagics5);
	}
	if(GetY>=maxy){
	SetAngle(-GetAngle);
	SetY(GetY-GetCommonData("Speed"));
		loop(5){
		let angle=-90+rand(-80,80);
		CreateShot12(GetX,GetY,2*cos(angle),rand(-1,-2.5),-0.01*cos(angle),0.05,0.1*cos(angle),rand(1.5,2.5),62,0);
		}
	PlaySE(SEmagics5);
	}
}

if(time%120==0 && time>=60){
let shot1=0;
let angle=0;
let speed=1.5;
let color=0;
SetShotDirectionType(PLAYER);
	loop(3){
		loop(15){
		CreateShotA(shot1,GetX+15,GetY-35,20);
		SetShotDataA(shot1,0,speed,angle,0,-0.02,0,color+74);
		SetShotDataA(shot1,60,0,0,0,0.1,4,color+74);
		FireShot(shot1);
		angle+=360/15;
		}
	speed-=0.5;
	color+=1;
	}
SetShotDirectionType(ABSOLUTE);
usespell=25;
PlaySE(SEshotb5);
}
if((time-80)%120==0 && time>=120){ PlaySE(SEshots5); }

} //Lunatic


newx=GetX;
if(newx<oldx){ movedir=1; }
if(newx>oldx){ movedir=2; }
oldx=GetX;

if(GetCommonData("Speed")>=3.6 && charge==0){
	SetColor(255,90,40);
	Concentration01(90);
	SetColor(255,255,255);
	charge=1;
}

if(time%3==0 && GetCommonData("Speed")>=4){
let xsize=128;
let ysize=128;
	effect1=(Obj_Create(OBJ_EFFECT));
	Obj_SetPosition(effect1,GetX,GetY);
	ObjEffect_SetLayer(effect1,1);
	ObjEffect_SetTexture(effect1,GRfade);
	ObjEffect_SetRenderState(effect1,ADD);
	ObjEffect_SetPrimitiveType(effect1,PRIMITIVE_TRIANGLESTRIP);
	ObjEffect_CreateVertex(effect1,4);
	if(usespell>=1){
	ObjEffect_SetVertexXY(effect1,0,-(xsize/2),-(ysize/2)); ObjEffect_SetVertexUV(effect1,0,384,0);
	ObjEffect_SetVertexXY(effect1,1,xsize/2,-(ysize/2)); ObjEffect_SetVertexUV(effect1,1,384+xsize,0);
	ObjEffect_SetVertexXY(effect1,2,-(xsize/2),ysize/2); ObjEffect_SetVertexUV(effect1,2,384,ysize);
	ObjEffect_SetVertexXY(effect1,3,xsize/2,ysize/2); ObjEffect_SetVertexUV(effect1,3,384+xsize,ysize);
	}
	if(usespell==0){
		if(movedir==1){
		ObjEffect_SetVertexXY(effect1,0,-(xsize/2),-(ysize/2)); ObjEffect_SetVertexUV(effect1,0,128,0);
		ObjEffect_SetVertexXY(effect1,1,xsize/2,-(ysize/2)); ObjEffect_SetVertexUV(effect1,1,128+xsize,0);
		ObjEffect_SetVertexXY(effect1,2,-(xsize/2),ysize/2); ObjEffect_SetVertexUV(effect1,2,128,ysize);
		ObjEffect_SetVertexXY(effect1,3,xsize/2,ysize/2); ObjEffect_SetVertexUV(effect1,3,128+xsize,ysize);
		}
		if(movedir==2){
		ObjEffect_SetVertexXY(effect1,0,-(xsize/2),-(ysize/2)); ObjEffect_SetVertexUV(effect1,0,256,0);
		ObjEffect_SetVertexXY(effect1,1,xsize/2,-(ysize/2)); ObjEffect_SetVertexUV(effect1,1,256+xsize,0);
		ObjEffect_SetVertexXY(effect1,2,-(xsize/2),ysize/2); ObjEffect_SetVertexUV(effect1,2,256,ysize);
		ObjEffect_SetVertexXY(effect1,3,xsize/2,ysize/2); ObjEffect_SetVertexUV(effect1,3,256+xsize,ysize);
		}
	}
	ObjEffect_SetVertexColor(effect1,0,80,255,255,255); ObjEffect_SetVertexColor(effect1,1,80,255,255,255);
	ObjEffect_SetVertexColor(effect1,2,80,255,255,255); ObjEffect_SetVertexColor(effect1,3,80,255,255,255);
	object1=object1~[effect1];
	timer1=timer1~[effect1];
}

if(time==0){ loop(1500){ timer1=timer1~[effect1]; } }

if(GetCommonData("Speed")>=4){
let i=0;
	while (i<length(object1)){
		timer1[i]=timer1[i]+1;
		ObjEffect_SetVertexColor(object1[i],0,80-(timer1[i]*4),255,255,255); ObjEffect_SetVertexColor(object1[i],1,80-(timer1[i]*4),255,255,255);
		ObjEffect_SetVertexColor(object1[i],2,80-(timer1[i]*4),255,255,255); ObjEffect_SetVertexColor(object1[i],3,80-(timer1[i]*4),255,255,255);
			if(timer1[i]>=12){
			Obj_Delete(object1[i]);
			object1=erase(object1,i); timer1=erase(timer1,i); i--;
			}
	i++;
	}
}

time++;
frame++;

if(GetCommonData("UseSpell1")>0){ usespell=GetCommonData("UseSpell1"); SetCommonData("UseSpell1",0); }
if(usespell>0){ usespell--; }
if(usespell<0){ usespell++; }

SetCommonData("Boss1X",GetX); SetCommonData("Boss1Y",GetY);
}

@DrawLoop{
	SetGraphicScale(1,1);
	SetTexture(GRboss);
	SetGraphicAngle(0,0,0);
	SetColor(255,255,255);
	SetRenderState(ALPHA);

	if(usespell>=1){ SetGraphicRect(384,outfit,512,outfit+128); }
	if(usespell<=-1){ SetGraphicRect(512,outfit,640,outfit+128); }

	if(usespell==0){
		if(movedir==0){ SetGraphicRect(0,outfit,128,outfit+128); }
		else if(movedir==1){ SetGraphicRect(128,outfit,256,outfit+128); }
		else if(movedir==2){ SetGraphicRect(256,outfit,384,outfit+128); }
	}
	if(GetLife>0){ DrawGraphic(GetX,GetY); }
}

@Finalize{
	if(GetCommonData("Difficulty")<3){ CreateEnemyFromFile("script\Functions\dispel.txt",GetX,GetY,0,0,"Sayuri"); }
}

}